package cn._2dland.utils
{
	public final class VideoUtils
	{
		/** 视频缓存时间 */
		public static const BUFFER_TIME:Number = 5;
		/** 默认音量 */
		public static const DEFAULT_VOLUMN:Number = 0.7;
		/** 视频缓冲检查周期 */
		public static const BUFFER_UPDATE_INTERVAL:Number = 500;
		/** 视频播放头更新周期 */
		public static const PLAYHEAD_UPDATE_INTERVAL:Number = 50;

		/** 缺省视频标题 */
		public static const DEFAULT_NAME:String = "视频悲剧了╮(╯▽╰)╭";
		/** 缺省视频地址 */
		public static const DEFAULT_URL:String = "http://www.2dland.cn/watch/null.mp4";
		/** 缺省视频长度 */
		public static const DEFAULT_DURATION:Number = 5013.333333333334;

		public function VideoUtils(){}

		/**
		 * 格式化时间
		 * @param time - 视频时间
		 * @param precision - 是否提高显示精度
		 * @return 时间字符串
		 */
		public static function formatMillisecond(time:Number, precision:Boolean=false):String {
			var showTime:Number = Math.floor(time / 1000);
			var tenthSecond:int = Math.floor(time % 1000 / 100);

			var seconds:int = showTime % 60;
			var minutes:int = Math.floor(showTime / 60) % 60;
			var hours:int = Math.floor(showTime / 3600);

			var secondStr:String = (seconds + 100).toString().substr(1);
			var minuteStr:String = (minutes + 100).toString().substr(1);
			
			var timeStr:String = minuteStr + ":" + secondStr;
			if(hours > 0) {
				timeStr = hours.toString() + ":" + timeStr;
			}
			if(precision) {
				timeStr += tenthSecond;
			}

			return timeStr;
		}
	}
}